﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;



namespace NetMove01
{
    public enum ERole {None, Client, Server}

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct SendData
    {
        public int x;
        public int y;

        public byte[] ToBytes()
        {
            Byte[] bytes = new Byte[Marshal.SizeOf(typeof(SendData))];
            GCHandle pinStructure = GCHandle.Alloc(this, GCHandleType.Pinned);
            try
            {
                Marshal.Copy(pinStructure.AddrOfPinnedObject(), bytes, 0, bytes.Length);
                return bytes;
            }
            finally
            {
                pinStructure.Free();
            }
        }
    } 

    public class NetBase
    {
        public Socket Handle;
        public ERole Role;

        public virtual void Start(ERole er) 
        {
            Role = er;
        
        }

        public virtual void Send(SendData sd) 
        {
        
        }

        public virtual void Receive(out SendData sd) 
        {
            sd.x = 0;
            sd.y = 0;
        
        }

    }
}
